package com.siyu.rehearsal.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.siyu.basedata.plan.domain.Plan;
import com.siyu.basedata.plan.service.IPlanService;
import com.siyu.common.core.controller.BaseController;
import com.siyu.common.core.domain.AjaxPageResult;
import com.siyu.common.core.domain.AjaxResult;
import com.siyu.rehearsal.dto.PlanPreviewDto;
import com.siyu.rehearsal.previewaffectv.service.impl.PreviewAffectVServiceImpl;
import com.siyu.rehearsal.previewpparameters.service.impl.PreviewPParametersServiceImpl;
import com.siyu.rehearsal.previewresult.service.impl.PreviewResultServiceImpl;
import com.siyu.rehearsal.previewriska.service.impl.PreviewRiskAServiceImpl;
import com.siyu.rehearsal.service.PlanManageService;
import com.siyu.rehearsal.vo.PlanVo;
import com.siyu.rehearsal.vo.PreviewPResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/rehearsal/manage")
public class PlanManageController extends BaseController {


    @Autowired
    private PreviewPParametersServiceImpl previewPParametersService;

    @Autowired
    private PreviewAffectVServiceImpl previewAffectVService;

    @Autowired
    private PreviewResultServiceImpl previewResultService;

    @Autowired
    private PreviewRiskAServiceImpl previewRiskAService;

    @Autowired
    private PlanManageService planManageService;

    @Autowired
    private IPlanService planService;

    /**
     * 预演方案列表查询
     *
     * @param planPreviewDto
     * @return
     */
    //@PostMapping("/plan/list")
    public AjaxResult getPlanPreview1(@RequestBody PlanPreviewDto planPreviewDto) {
        AjaxPageResult ajaxPageResult = planManageService.getPlanPreview(planPreviewDto);
        return AjaxResult.success(ajaxPageResult);
    }
    @PostMapping("/plan/list")
    public AjaxResult getPlanPreview(@RequestBody PlanPreviewDto planPreviewDto) {
        HashMap<String, ArrayList<PlanVo>> planResultMap = planManageService.getPlan(planPreviewDto);
        return AjaxResult.success(planResultMap);
    }



    /**
     * 打开方案
     * @param id
     * @return
     */
    @GetMapping("/plan/initialize")
    public AjaxResult getOpenPlan(@RequestParam("id") String id) {
        PreviewPResultVo previewPResultVo = planManageService.getOpenPlan(id);
        return AjaxResult.success(previewPResultVo);
    }

    /**
     * 删除方案
     * @param ids
     * @return
     */

    @DeleteMapping("/plan/delete")
    @Transactional
    public AjaxResult deletePlan(@RequestBody List<String> ids) {
        try {
            planManageService.deletePlan(ids);
        } catch (Exception e) {
            return AjaxResult.error("删除失败!");
        }
        return AjaxResult.success("删除成功!");
    }

}
